<template>
  <div id="tab_bar_item" @click="goto">
    <div class="item_icon" :class="{ active: isActive }">
      <slot name="icon"></slot>
    </div>
    <div class="item_text">
      <slot name="text"></slot>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    link: {
      type: String,
      required: true
    }
  },
  computed: {
    isActive() {
      return this.$route.path.indexOf(this.link) !== -1;
    }
  },
  methods: {
    goto() {
      this.$router.replace(this.link);
    }
  }
};
</script>

<style lang="less" scoped>
#tab_bar_item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.item_icon {
  i {
    font-size: 20px;
  }
}
.item_text {
  font-size: var(--font-size);
}
.active {
  color: var(--color-base);
}
</style>
